package com.example.xmpic.ui.activity.bind;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.example.common.base.BaseBindActivity;
import com.example.xmpic.R;
import com.example.xmpic.databinding.ActivityConfigGuideBinding;

/**
 * @author skygge
 * @date 2020-02-18.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：配置网关说明
 */
public class CameraGuideActivity extends BaseBindActivity<ActivityConfigGuideBinding> {

    /** 没有网络 */
    private static final int NETWORK_TYPE_INVALID = 0;
    /** 移动网络 */
    private static final int NETWORK_TYPE_MOBILE = 3;
    /** wifi网络 */
    private static final int NETWORK_TYPE_WIFI = 4;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_config_guide;
    }

    @Override
    protected void initListener() {
        super.initListener();
        mDBind.ivAddMyIpcBack.setOnClickListener(view -> finish());
        mDBind.addMyPicNext.setOnClickListener(v -> {
            int netState = getNetWorkType(mContext);
            if (netState == NETWORK_TYPE_WIFI){
                skipAnotherActivity(CameraConfigInNetActivity.class);
                finish();
            }else {
                showToast(getString(R.string.no_wifi));
            }
        });
    }

    /**
     * 获取网络状态
     */
    public static int getNetWorkType(Context context) {
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = manager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected()) {
            String type = networkInfo.getTypeName();
            if (type.equalsIgnoreCase("WIFI")) {
                return  NETWORK_TYPE_WIFI;
            } else if (type.equalsIgnoreCase("MOBILE")) {
                return  NETWORK_TYPE_MOBILE;
            }
        } else {
            return  NETWORK_TYPE_INVALID;
        }
        return NETWORK_TYPE_INVALID;
    }
}
